﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

public static class TinyLib
{
    //public static string ToAlias(string text)
    //{
    //    return RemoveSpecialChar(text).Replace(" ", "-");
    //}

  

  public static string VNDate(string strDate)
  {
      return DateTime.Parse(strDate).ToString("dd/MM/yyyy");
  }
    public static string GetConfigKey(string webconfigKey)
    {
        try
        {
            return System.Web.Configuration.WebConfigurationManager.AppSettings[webconfigKey].ToString();
        }
        catch
        {
            return "";
        }
    }
    public static string GetSettingKey(string settingKey)
    {
        try
        {
            return "";
        }
        catch { return ""; }
    }
    //public static string RemoveSpecialChar(string text)
    //{
    //    var result = VNToEN(text).Replace("&", " va ").ToLower().ToArray();
    //    var array = result.ToArray();
    //    for (int i = 0; i < array.Length; i++)
    //    {
    //        int ascii = (int)array[i];
    //        if ((ascii > 96 && ascii < 123) || (ascii > 47 && ascii < 58))
    //        {
    //        }
    //        else
    //        {
    //            result[i] = ' ';
    //        }
    //    }
    //    var result1 = string.Join("", result);
    //    while (result1.IndexOf("  ") > 0)
    //    {
    //        result1 = result1.Replace("  ", " ");
    //    }
    //    return result1.Trim();
    //}

    /// <summary>
    /// Return path of file
    /// </summary>
    /// <param name="image"></param>
    /// <param name="name"></param>
    /// <returns></returns>

    public static void DeleteFile(string path)
    {
        if (File.Exists(path))
            File.Delete(path);
    }

    private static string[] VietnameseSigns = new string[] { "aAeEoOuUiIdDyY", "áàạảãâấầậẩẫăắằặẳẵ", "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ", "éèẹẻẽêếềệểễ", "ÉÈẸẺẼÊẾỀỆỂỄ", "óòọỏõôốồộổỗơớờợởỡ", "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ", "úùụủũưứừựửữ", "ÚÙỤỦŨƯỨỪỰỬỮ", "íìịỉĩ", "ÍÌỊỈĨ", "đ", "Đ", "ýỳỵỷỹ", "ÝỲỴỶỸ" };
    public static string VNToEN(string strVN)
    {
        for (int i = 1; i < VietnameseSigns.Length; i++)
        {
            for (int j = 0; j < VietnameseSigns[i].Length; j++)
            {
                strVN = strVN.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
            }

        }
        return strVN;
    }
}